# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: AlexWMF <alexxwmf@gmail.com>

_realname=qwt
pkgbase=mingw-w64-${_realname}-qt4
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-qt4"
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=6.1.2
pkgrel=2
pkgdesc="Qt Widgets for Technical Applications for Qt4 (mingw-w64)"
arch=('any')
license=("custom:${_realname}")
url="https://qwt.sourceforge.io/"
depends=("${MINGW_PACKAGE_PREFIX}-qt4")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-make")
options=(!strip staticlibs !buildflags)
install=${_realname}-qt4-${CARCH}.install
source=("https://downloads.sourceforge.net/${_realname}/${_realname}-${pkgver}.tar.bz2"
        "qwtconfig-msys2.pri")
sha256sums=('2b08f18d1d3970e7c3c6096d850f17aea6b54459389731d3ce715d193e243d0c'
            '8a76dc8dbea21d1745628fa77a41425a8db79d3f741db02995d27818f5726506')

prepare() {
  local _buildpkgdir=${pkgdirbase}/${pkgname}${MINGW_PREFIX}
  mkdir -p ${_buildpkgdir}
  local PREFIX_WIN=$(cygpath -am ${_buildpkgdir})

  cd ${srcdir}/${_realname}-${pkgver}
  # copy our config file to the right place
  cp ${srcdir}/qwtconfig-msys2.pri qwtconfig.pri
  sed -s "s|%VALUE_QWT_INSTALL_PREFIX%|${PREFIX_WIN}|g" \
    -i qwtconfig.pri
}

build() {
  cd ${srcdir}/${_realname}-${pkgver}
  ${MINGW_PREFIX}/bin/qmake qwt.pro

  make # VERBOSE=1
}

package() {
  cd ${srcdir}/${_realname}-${pkgver}
  make -j1 install

  mkdir -p ${pkgdir}${MINGW_PREFIX}/bin/
  mv "${pkgdir}${MINGW_PREFIX}"/lib/*.dll "${pkgdir}${MINGW_PREFIX}"/bin/

  local PREFIX_WIN=$(cygpath -am ${pkgdir}${MINGW_PREFIX})

  sed -s "s|${PREFIX_WIN}|${MINGW_PREFIX}|g" \
    -i ${pkgdir}${MINGW_PREFIX}/share/qt4/mkspecs/features/qwtconfig.pri
}
